package demo03;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/*
 * 1.添加圆形 2. 添加矩形 3. 计算所有面积 4. 退出
控制台测试，添加图形，输出所有面积
 */
public class homework01 {
	public static void main(String[] args) {
        List<Shape> shapes = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        int choice;

        do {
            System.out.println("1. 添加圆形 2. 添加矩形 3. 计算所有面积 4. 退出");
            choice = scanner.nextInt();

            switch (choice) {
                case 1:
                    System.out.print("输入半径: ");
                    double radius = scanner.nextDouble();
                    shapes.add(new Circle(radius));
                    break;
                case 2:
                    System.out.print("输入长和宽: ");
                    double length = scanner.nextDouble();
                    double width = scanner.nextDouble();
                    shapes.add(new Rectangle(length, width));
                    break;
                case 3:
                    for (Shape shape : shapes) {
                        if (shape instanceof Circle) {
                            System.out.printf("圆形面积：%.6f\n", shape.calculateArea());
                        } else if (shape instanceof Rectangle) {
                            System.out.printf("矩形面积：%.6f\n", shape.calculateArea());
                        }
                    }
                    break;
                case 4:
                    System.out.println("退出程序");
                    break;
                default:
                    System.out.println("无效选项，请重新输入");
            }
        } while (choice != 4);

        scanner.close();
    }
}
